(defpackage #:lilu-apropos-tests
  (:use #:cl #:fiveam #:lilu-apropos))

(in-package #:lilu-apropos-tests)

(def-suite lilu-apropos-system
  :description "Test lilu-apropos system")

(in-suite lilu-apropos-system)
;;;
(defvar tt-var
  nil
  "tt-var")

(defvar tt nil "tt-var")
(defun tt ()
  "tt-fun"
  0)

;;;

(defvar iap (make-instance 'iapropos))

(test package
  (setf (iapropos-package-text iap) "lilu-apropos-tests")
  (format *debug-io* "~A~%" (iapropos-matching-packages iap))
  (is (equal (iapropos-matching-packages iap) (list (find-package :lilu-apropos-tests)))))

(test var
  (setf (iapropos-package-text iap) "lilu-apropos-tests")
  (setf (iapropos-symbol-text iap) "tt-var")
  (is (equal (iapropos-matching-symbols iap) (list (find-symbol "TT-VAR" (find-package :lilu-apropos-tests))))))

(test var-type
  (let ((sym (find-symbol "TT-VAR" (find-package :lilu-apropos-tests))))
    (is (equal (list-symbol-bounding-types sym) (list :variable)))))

(test var-doc
  (let ((sym (find-symbol "TT-VAR" (find-package :lilu-apropos-tests))))
    (is (equal (symbol-documentation sym :variable) "tt-var"))))

(test var-loc
  (let ((sym (find-symbol "TT-VAR" (find-package :lilu-apropos-tests))))
    (is (equal (lilu-apropos::symbol-location sym :variable)
               (cons "/home/gas/.roswell/local-projects/my/lilu-apropos/tests/test.lisp"  219)))))

(test sym-tt
  (setf (iapropos-package-text iap) "lilu-apropos-tests")
  (setf (iapropos-symbol-text iap) "^tt$")
  (is (equal (iapropos-matching-symbols iap) (list (find-symbol "TT" (find-package :lilu-apropos-tests))))))

(test sym-tt-type
  (let ((sym (find-symbol "TT" (find-package :lilu-apropos-tests))))
    (is (equal (list-symbol-bounding-types sym) (list :variable :function)))))

(test sym-tt-doc
  (let ((sym (find-symbol "TT" (find-package :lilu-apropos-tests))))
    (is (equal (symbol-documentation sym :variable) "tt-var"))
    (is (equal (symbol-documentation sym :function) "tt-fun"))
    ))

(test sym-tt-loc
  (let ((sym (find-symbol "TT" (find-package :lilu-apropos-tests))))
    (is (equal (lilu-apropos::symbol-location sym :variable)
               (cons "/home/gas/.roswell/local-projects/my/lilu-apropos/tests/test.lisp"  253)))
    (is (equal (lilu-apropos::symbol-location sym :function)
               (cons "/home/gas/.roswell/local-projects/my/lilu-apropos/tests/test.lisp"  278)))))

;;;
;;;
;;;

(defun run-tests ()
  (run! 'lilu-apropos-system))
